/**
 * SharedPreference.java
 * com.jamin.aabill.sharepref
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-8-22 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
 */

package com.jamin.aabill.sharepref;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * ClassName:SharedPreference
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-8-22 上午9:03:46 
 */
public class SharedPref{

	
	private SharedPreferences mSharedPreferences = null;
	private Editor mEditor = null;
	private static SharedPref sharePref = null;
	

	/**
	 * register in Application
	 * @method getInstance
	 * @param PREF_NAME
	 * @param ctx
	 * @return
	 * @throws 
	 * @since v1.0
	 */
	public synchronized static SharedPref getInstance(String PREF_NAME , Context ctx){
		if(sharePref != null){
			return sharePref;
		}else{
			return new SharedPref(PREF_NAME , ctx);
		}

	}
	
	private SharedPref(String PREF_NAME, Context ctx){
		mSharedPreferences = ctx.getSharedPreferences(PREF_NAME , Activity.MODE_PRIVATE);
		mEditor = mSharedPreferences.edit();
	}
	

	
	public String getSharePrefString(String key){
		return mSharedPreferences.getString(key, ""); 
	}
	
	
	
	public boolean getSharePrefBoolean(String key){
		return mSharedPreferences.getBoolean(key, false); 
	}
	
	
	
	public int getSharePrefInteger(String key){
		return mSharedPreferences.getInt(key, -1);
	}
	
	
	
	public long getSharePrefLong(String key){
		return mSharedPreferences.getLong(key, -1); 
	}
	
	
	
	public float getSharePrefFloat(String key){
		return mSharedPreferences.getFloat(key, -1);
	}
	

	public void putSharePrefString(String key , String value){
		mEditor.putString(key, value);
		mEditor.commit();
	}
	
	public void putSharePrefBoolean(String key , boolean value){
		mEditor.putBoolean(key, value);
		mEditor.commit();
	}
	
	public void putSharePrefFloat(String key , float value){
		mEditor.putFloat(key, value);
		mEditor.commit();
	}
	
	public void putSharePrefLong(String key , long value){
		mEditor.putLong(key, value);
		mEditor.commit();
	}
	
	public void putSharePrefInteger(String key , int value){
		mEditor.putInt(key, value);
		mEditor.commit();
	}
	
	
	
}

